
package ch.hearc.coursJava.GUI.j2D.tableAnimerHSB.swings;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;

import ch.hearc.coursJava.GUI.j2D.tableAnimerHSB.settings.AnimationType;

public class JPanelControlAnimation extends JPanel
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public JPanelControlAnimation(JPanelDessin panelDessin)
		{
		this.panelDessin = panelDessin;

		this.createComponents();
		this.addListeners();
		this.addComponents();

		this.panelRadioButton.setBorder(BorderFactory.createTitledBorder("Animation"));
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public void setDefaultRadioButton()
		{
		this.radioAnimationNone.setSelected(true);
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void createComponents()
		{
		this.panelRadioButton = new JPanel();

		this.radioGroup = new ButtonGroup();

		this.radioAnimationAlpha = new JRadioButtonAnimation("Alpha", AnimationType.ALPHA);
		this.radioAnimationHue = new JRadioButtonAnimation("Hue", AnimationType.HUE);
		this.radioAnimationHueAlpha = new JRadioButtonAnimation("Hue_Alpha", AnimationType.HUE_ALPHA);
		this.radioAnimationNone = new JRadioButtonAnimation("None", AnimationType.NONE);

		this.btnReset = new JButton("Reset");

		this.setDefaultRadioButton();
		}

	private void addListeners()
		{
		ActionListener radioAction = new ActionListener()
			{

				@Override
				public void actionPerformed(ActionEvent e)
					{
					JRadioButtonAnimation radio = (JRadioButtonAnimation)e.getSource();
					panelDessin.animerImage(radio.getAnimationType());
					}
			};

		this.radioAnimationAlpha.addActionListener(radioAction);
		this.radioAnimationHue.addActionListener(radioAction);
		this.radioAnimationHueAlpha.addActionListener(radioAction);
		this.radioAnimationNone.addActionListener(radioAction);

		this.btnReset.addActionListener(new ActionListener()
			{

				@Override
				public void actionPerformed(ActionEvent arg0)
					{
					panelDessin.resetImage();
					setDefaultRadioButton();
					}
			});
		}

	private void addComponents()
		{
		this.radioGroup.add(radioAnimationAlpha);
		this.radioGroup.add(radioAnimationHue);
		this.radioGroup.add(radioAnimationHueAlpha);
		this.radioGroup.add(radioAnimationNone);

		this.panelRadioButton.add(radioAnimationNone);
		this.panelRadioButton.add(radioAnimationHue);
		this.panelRadioButton.add(radioAnimationHueAlpha);
		this.panelRadioButton.add(radioAnimationAlpha);

		this.add(panelRadioButton);

		this.add(btnReset);
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	// Tools
	private JRadioButtonAnimation radioAnimationAlpha;
	private JRadioButtonAnimation radioAnimationHue;
	private JRadioButtonAnimation radioAnimationHueAlpha;
	private JRadioButtonAnimation radioAnimationNone;

	private ButtonGroup radioGroup;
	private JButton btnReset;

	private JPanel panelRadioButton;

	// Input
	private JPanelDessin panelDessin; // Necessaire pour pouvoir appeler la methode animerImage()

	}
